<template>
  <div class="advance-table-body">
    <!--搜索栏-->
    <el-form class="search-form--inset" ref="elForm" :model="queryParams" inline size="small" label-width="100px" label-position="left">
      <el-form-item label="用户账号">
        <el-input v-model="queryParams.userName" placeholder="请输入" :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item label="注册时间">
        <el-date-picker
          v-model="queryParams.date"
          type="daterange"
          @change="zcTimeChange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="账号状态">
        <el-select v-model="queryParams.status">
          <el-option label="正常" value="0"></el-option>
          <el-option label="禁用" value="1"></el-option>
        </el-select>
      </el-form-item>
      <trust-query-filter-operation :searchAdvanced.sync="searchAdvanced" @query="searchAction" @reset="resetAction"></trust-query-filter-operation>
    </el-form>
    <!--操作栏-->
    <div class="table-operator">
      <el-button type="primary" size="small" plain @click="clickBtnExport">导出</el-button>
    </div>
    <!--表格-->
    <el-table
      class="k-table"
      ref="table"
      @selection-change="handleSelectionChange"
      :data="tableList"
      v-loading="loading"
      show-summary
      :summary-method="getSummaries"
    >
      <el-table-column label="多选" type="selection" align="center" fixed width="60" />
      <el-table-column label="序号" type="index" :formatter="fIndex" align="center" fixed width="60" />
      <el-table-column label="用户ID" align="left" prop="id" min-width="100px" show-overflow-tooltip />
      <el-table-column label="用户账号" align="left" prop="userName" min-width="120px" show-overflow-tooltip />
      <el-table-column label="绑定QQ" align="left" prop="qq" min-width="80" show-overflow-tooltip />
      <el-table-column label="注册时间" align="left" prop="registerTime" show-overflow-tooltip min-width="100"/>
      <el-table-column label="剩余点数" align="left" prop="remainingPoints" min-width="80" show-overflow-tooltip />
      <el-table-column label="消耗点数" align="left" prop="costPoints" min-width="80" show-overflow-tooltip />
      <el-table-column label="充值点数" align="left" prop="topUpPoints" min-width="80" show-overflow-tooltip />
      <el-table-column label="充值金额" align="left" prop="topUpMoney" min-width="80" show-overflow-tooltip />
      <el-table-column label="卡号信息" align="left" prop="cardNo" min-width="120" show-overflow-tooltip />
      <el-table-column label="登录IP地址" align="left" prop="lastLoginIp" min-width="120" show-overflow-tooltip />
      <el-table-column label="mac地址" align="left" prop="macNo" min-width="120" show-overflow-tooltip />
      <el-table-column label="邀请码" align="left" prop="invitationCode" min-width="80" show-overflow-tooltip />
      <el-table-column label="最后登录日期" align="left" prop="lastLoginTime" min-width="120" show-overflow-tooltip />
      <el-table-column label="账户状态" align="left" prop="status" :formatter="fStatus" min-width="80" show-overflow-tooltip />
      <el-table-column label="操作" align="center" width="120" fixed="right">
        <template #default="{ row }">
          <el-button type="text" @click="clickBtnEdit(row)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <trust-pagination
      :total="total"
      :page-size.sync="queryParams.pageSize"
      :current-page.sync="queryParams.pageNum"
      @size-change="handleSizeChange" @current-change="handleCurrentChange"></trust-pagination>
    <user-list-dialog ref="userListDialogRef"></user-list-dialog>
  </div>
</template>
<script>
import { saTableMixin } from '@/views/custom/mixin/saTableMixin';
import UserListDialog from '@/views/custom/userManage/userList/userListDialog.vue';
import zTool from '@/views/custom/tool/z-date.js'
import request from '@/utils/request';

export default {
  name: "userList",//用户列表
  components: { UserListDialog },
  mixins: [saTableMixin],
  data() {
    return {
      rules: [],
      options: [],
    }
  },
  mounted() {
    this.requestData("/user_info/list","get",this.queryParams);
  },
  methods:{
    clickBtnExport(){
      this.requestDataExport();
    },
    clickBtnEdit(row){
      this.$refs.userListDialogRef.openDiaolog(row.id,()=>{
        this.refreshTableData();
      });
    },
    //网络-导出
    requestDataExport(){
      request({
        url:`/user_info/export`,
        method:'post',
        data: {},
      }).then(response =>{

      })
    },
    //注册时间变化回调
    zcTimeChange(val){
      this.queryParams.queryStartTime = zTool.toFormatString("yyyy-MM-dd",val[0]);
      this.queryParams.queryEndTime = zTool.toFormatString("yyyy-MM-dd",val[1]);
    },
    fStatus(row, column, cellValue, index){
      if (cellValue === "0"){
        return "正常";
      }else {
        return "禁用"
      }
    },
    getSummaries(param){
      const { columns, data } = param;
      const sums = [];
      // console.log("=====",param);
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        }
        if (column.property === "remainingPoints"||column.property === "costPoints"||column.property === "topUpPoints"||column.property === "topUpMoney"){
          const values = data.map(item => Number(item[column.property]));
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += '';
        }else {
          sums[index] = '';
        }
      });
      return sums;
    }
  }
}
</script>
